{% set pypi_name = 'openstacksdk' %}
{% set upstream_version = upstream_version('0.52.0') %}
{% set rpm_release = '1' %}
{% set source = url_pypi() %}
# FIXME(jpena): unit tests require way too much memory
# and cause timeouts due to swapping. Disabling for now
%define with_tests 0
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        An SDK for building applications to work with OpenStack
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/{{ pypi_name }}
Source0:        {{ source }}
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('PyYAML') }}
BuildRequires:  {{ py3('appdirs') }}
BuildRequires:  {{ py3('beautifulsoup4') }}
BuildRequires:  {{ py3('ddt') }}
BuildRequires:  {{ py3('decorator') }}
BuildRequires:  {{ py3('deprecation') }}
BuildRequires:  {{ py3('dogpile.cache') }}
BuildRequires:  {{ py3('extras') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('jmespath') }}
BuildRequires:  {{ py3('jsonpatch') }}
BuildRequires:  {{ py3('jsonschema') }}
BuildRequires:  {{ py3('keystoneauth1') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('munch') }}
BuildRequires:  {{ py3('netifaces') }}
BuildRequires:  {{ py3('os-service-types') }}
BuildRequires:  {{ py3('oslo.config') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('python-subunit') }}
BuildRequires:  {{ py3('requests-mock') }}
BuildRequires:  {{ py3('requestsexceptions') }}
BuildRequires:  {{ py3('six') }}
BuildRequires:  {{ py3('statsd') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('stevedore') }}
BuildRequires:  {{ py3('testscenarios') }}
BuildRequires:  {{ py3('testtools') }}
BuildArch:      noarch
%if 0%{?suse_version}
# RDO does not package prometheus_client
BuildRequires:  {{ py3('prometheus_client') }}
%endif

%description
The openstacksdk is a library for building applications to work
with OpenStack clouds.
The project aims to provide a consistent and complete set of
interactions with OpenStack's many services, along with complete
documentation, examples, and tools.

%package -n {{ py2name(py_versions='py3') }}
Summary:        An SDK for building applications to work with OpenStack
Requires:       {{ py3('PyYAML') }}
Requires:       {{ py3('appdirs') }}
Requires:       {{ py3('cryptography') }}
Requires:       {{ py3('decorator') }}
Requires:       {{ py3('dogpile.cache') }}
Requires:       {{ py3('iso8601') }}
Requires:       {{ py3('jmespath') }}
Requires:       {{ py3('jsonpatch') }}
Requires:       {{ py3('keystoneauth1') }}
Requires:       {{ py3('munch') }}
Requires:       {{ py3('netifaces') }}
Requires:       {{ py3('os-service-types') }}
Requires:       {{ py3('requestsexceptions') }}
Requires:       {{ py3('six') }}
%if 0%{?suse_version}
Obsoletes:      {{ py2name(py_versions='py2') }} < 1.0.0
%endif
%if 0%{?suse_version}
%if 0%{?sle_version} >= 150000 || 0%{?suse_version} > 1500
Requires:       mkisofs
%else
Requires:       genisoimage
%endif
%else
Requires:       genisoimage
%endif

%description -n {{ py2name(py_versions='py3') }}
The openstacksdk is a library for building applications to work
with OpenStack clouds.
The project aims to provide a consistent and complete set of
interactions with OpenStack's many services, along with complete
documentation, examples, and tools.

This package contains the Python 3.x module

%package -n python-openstacksdk-doc
Summary:        %{summary} - Documentation
Group:          Documentation/HTML
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('sphinxcontrib-svg2pdfconverter') }}

%description -n python-openstacksdk-doc
The openstacksdk is a library for building applications to work
with OpenStack clouds.
The project aims to provide a consistent and complete set of
interactions with OpenStack's many services, along with complete
documentation, examples, and tools.

The openstacksdk is a collection of libraries for building
applications to work with OpenStack clouds.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup
sed -i -e 's,coverage.*,,' test-requirements.txt || true
sed -i -e "s,'sphinx.ext.intersphinx'\,,," doc/source/conf.py
%if !0%{?suse_version}
# RDO does not package prometheus_client
rm openstack/tests/unit/test_stats.py
%endif

%build
%py3_build
PBR_VERSION={{ upstream_version }} %sphinx_build -b html doc/source doc/build/html
rm -rf doc/build/html/.{doctrees,buildinfo}

%install
%py3_install

%if 0%{?with_tests}
%check
export OS_LOG_CAPTURE=true
export OS_TEST_TIMEOUT=30
python3 -m stestr.cli run
%endif

%files -n {{ py2name(py_versions='py3') }}
%license LICENSE
%doc ChangeLog README.rst
%{_bindir}/openstack-inventory
%{python3_sitelib}/openstack
%{python3_sitelib}/*.egg-info

%files -n python-openstacksdk-doc
%license LICENSE
%doc doc/build/html

%changelog
